package com.lianrui.app.cart.controller;

import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.lianrui.app.cart.domain.Cart;
import com.lianrui.app.cart.service.ICartService;
import com.lianrui.app.cart.vos.CartItemVO;
import com.lianrui.app.cart.vos.CartPage;
import com.lianrui.commons.ResultView;
import com.lianrui.commons.exception.BusinessException;
import com.lianrui.core.AbstractController;
import com.lianrui.core.IService;

/**
 * 功能描述：购物车控制器
 * @author Administrator
 *
 */
@Controller
@RequestMapping("/cart")
public class CartController extends AbstractController<CartPage, Cart, Integer>{
	private static final Logger LOGGER = LoggerFactory.getLogger(CartController.class);
	
	@Autowired
	private ICartService cartService;
	
	
	/**
	 * 获取会员的购物车列表
	 * @param cart
	 * @return
	 */
	@RequestMapping("/all/{member_id}")
	@ResponseBody
	public ResultView<List<CartItemVO>> all(@PathVariable String member_id){
		ResultView<List<CartItemVO>> view = new ResultView<List<CartItemVO>>();
		try {
			view.setResult(cartService.all(member_id));
		} catch (BusinessException e) {
			view.setCode(e.getCode());
			view.setMessage(e.getMessage());
		}
		return view;
	}
	
	
	@Override
	public IService<CartPage, Cart, Integer> getService() {

		return cartService;
	}

	@Override
	public Logger getLogger() {
		return LOGGER;
	}

}
